package com.mys.springboot.config;

import java.util.concurrent.Executors;

import javax.annotation.PostConstruct;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.stereotype.Controller;

import com.mys.springboot.Constants;

@Configuration
@EnableAutoConfiguration
@SpringBootApplication
@ComponentScan(value = "com.mys.springboot", excludeFilters = { @Filter(Controller.class),
		@Filter(type = FilterType.ASSIGNABLE_TYPE, value = { RootConfiguration.class }) })
public class RootConfiguration extends SpringBootServletInitializer implements EmbeddedServletContainerCustomizer {

	@Override
	public void customize(ConfigurableEmbeddedServletContainer container) {
		container.setPort(8001);
		container.setSessionTimeout(30);
	}

	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(RootConfiguration.class);
	}

	@PostConstruct
	public void postConstruct() {
		Constants.threadPool = Executors.newFixedThreadPool(20);
	}

}